package repertory.android.ericchen.androidrepertory.view;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import repertory.android.ericchen.androidrepertory.R;

/**弹框通用类
 * className:CommonDialog
 * author: Ericchen
 * description:
 * date: 2017/3/6 18:16
 * update: 2017/3/6
 * version:
 */
public class CommonDialog extends Dialog{
    private Context context;
    private TextView titleText;
    private TextView contentText;
    private Button leftBtn;
    private Button rightBtn;

    /**
     *
     * @param context
     * @param title 标题
     * @param content 内容
     * @param leftBtnText 第一个按钮文字
     * @param leftBtnListener 第一个按钮监听事件
     * @param rightBtnText  第二个按钮文字
     * @param rightBtnListener 第二个按钮监听事件
     */
    public CommonDialog(Context context,String title,String content,String leftBtnText,View.OnClickListener leftBtnListener,
                        String rightBtnText,View.OnClickListener rightBtnListener){
        super(context);
        setContentView(R.layout.common_dialog_layout);
        titleText =(TextView)findViewById(R.id.common_dialog_title_text);
        contentText =(TextView)findViewById(R.id.common_dialog_content_text);
        contentText.setText(content);
        leftBtn =(Button)findViewById(R.id.common_dialog_btn_cancel);
        leftBtn.setOnClickListener(leftBtnListener);
        rightBtn =(Button)findViewById(R.id.common_dialog_btn_ok);
        rightBtn.setOnClickListener(rightBtnListener);
        setTitle(title);
        setLeftBtn(leftBtnText);
        setRightBtn(rightBtnText);
    }

    public void setTitle(String title){
        if(TextUtils.isEmpty(title)){
            titleText.setVisibility(View.GONE);
        }else{
            titleText.setVisibility(View.VISIBLE);
            titleText.setText(title);
        }
    }

    public void setLeftBtn(String leftBtnText) {
        if(TextUtils.isEmpty(leftBtnText)){
            leftBtn.setVisibility(View.GONE);
        }else{
            leftBtn.setVisibility(View.VISIBLE);
            leftBtn.setText(leftBtnText);
        }
    }

    public void setRightBtn(String rightBtnText) {
        if(TextUtils.isEmpty(rightBtnText)){
            rightBtn.setVisibility(View.GONE);
        }else{
            rightBtn.setVisibility(View.VISIBLE);
            rightBtn.setText(rightBtnText);
        }
    }
}
